home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / yerk / mps231ss.hqx / Mops source / System source / FP test < prev    next >
Text File  |  1992-09-16  |  1KB  |  37 lines

  1. \ FP test.
  2. +echo
  3.  
  4. 2.3    fvalue    FV
  5.  
  6. 1.2    fcon    FC
  7.  
  8. \ One way to test our FP ops is to do a number of calculations with with a known result at the end.  The calculations should be simple enough that if we get the wrong answer, we've got a fighting chance of finding where things went wrong.  So here we check that  sin**2 (x) + cos**2 (x) = 1.  We square the sine and cos in two different ways and use different operand modes, in the hope that any bugs in the operand accessing will show themselves.  Also extra dummy local variables can be added or removed, to test correct use of the ExtraLocals area versus the D regs and FP regs.
  9.  
  10. : Q  { %angle \ %temp1 %temp2 %temp3 %temp4 -- b }
  11. db    %angle sin  -> %temp1
  12.     %angle cos  -> %temp2
  13.     %temp1 %temp1 f*  -> %temp3
  14.     %temp2 fdup f* -> %temp4
  15.     %temp3  %temp4  f+
  16.     1.0 f-
  17.     0.000000001 f< if  true  else  false  then  ;
  18.  
  19. : TEST1
  20.     0.2 q  .    room: fltmem  .    ;    \ Should print  -1 100
  21.     
  22. endload
  23.  
  24. \ Here's a timing test:
  25.  
  26. : TEST2  { \ %a %b %c %d -- }
  27.     global ticks @
  28.     100. -> %a  200. -> %b  300. -> %c  400. -> %d
  29.     100000 0 DO
  30.         %a %b f*  %c %d f*  f+
  31.         %a %d f+  f/  -> fv
  32.     LOOP
  33.     global ticks @ - negate . cr  fv e.
  34.     3 beep  ;
  35.  
  36. \ This takes 60 secs. on a IIsi (20 MHz 68030) without FPU.  With FPU, but still using SANE: 45 secs.  (SANE has a lot of overhead.)  With normal run-time FPU detection from Mops: 14.9 secs.  With compiled (optimized) FPU code in Mops: 3.1 secs.  The hand-coded assembly equivalent takes 1.5 secs.
  37.